//
//  StoresGoodsTableViewCell.m
//  TerritoryShopkeeper
//
//  Created by 李小龙 on 2017/12/19.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "StoresGoodsTableViewCell.h"
@interface StoresGoodsTableViewCell ()<UITextFieldDelegate>
{
    NSString *_countText;
}
@end

@implementation StoresGoodsTableViewCell
- (IBAction)addButtonAction:(id)sender {
    if (self.block) {
        self.block(StoresGoodCellClickTypeAdd, self.countTF.text);
    }
}
- (IBAction)subButtonAction:(id)sender {
    if (self.block) {
        self.block(StoresGoodCellClickTypeSub, self.countTF.text);
    }
}
- (void)chooseButtonAction:(id)sender {
    if (self.block) {
        self.block(StoresGoodCellClickTypeChoose, @"");
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self createUI];
}

- (void)createUI {
    [self.addButton setCircleWithColor:[UIColor colorWithHex:0xE5E5E5 alpha:1.0] borderWidth:1.0 cornerRadius:0];
    [self.subButton setCircleWithColor:[UIColor colorWithHex:0xE5E5E5 alpha:1.0] borderWidth:1.0 cornerRadius:0];
    [self.countTF setCircleWithColor:[UIColor colorWithHex:0xE5E5E5 alpha:1.0] borderWidth:1.0 cornerRadius:0];
    
    [self.countTF setDelegate:self];
    
    [self.contentView addSubview:self.chooseButton];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.chooseButton.frame = CGRectMake(self.width-50-9, self.height-25-9, 50, 25);
    [self.chooseButton setHalfCircleWithColor:[UIColor ThemeColor]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark - UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (![textField.text isEqualToString:_countText]) {
        _countText = textField.text;
        if (self.block) {
            self.block(StoresGoodCellClickTypeText, textField.text);
        }
    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - Get
- (RedPointButton *)chooseButton {
    if (!_chooseButton) {
        _chooseButton = [RedPointButton buttonWithType:UIButtonTypeCustom];
        [_chooseButton setTitle:@"选规格" forState:UIControlStateNormal];
        [_chooseButton setTitleColor:[UIColor ThemeColor] forState:UIControlStateNormal];
        [_chooseButton.titleLabel setFont:TextPingFangFontSize(12)];
        [_chooseButton addTarget:self action:@selector(chooseButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _chooseButton;
}
@end
